﻿using System;
using MediatR;
using SheepCultivation.API.AddliCation.AddressW;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Domain.Purchase_sales;
using SheepCultivation.Common.Domain.PurchaseSales;
using SheepCultivation.Common.Domain.Week2;
using SheepCultivation.Common.Domain.Week3;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace SheepCultivation.API.AddliCation.PurchaseSales
{
    public class SheepBuyCreateHandler : IRequestHandler<SheepBuyCreateCommon, Result>
    {
        public readonly IBaseRepository<SheepBuy> SheepBuyRepository;
        public SheepBuyCreateHandler(IBaseRepository<SheepBuy> sheepBuyRepository)
        {
            SheepBuyRepository= sheepBuyRepository;
        }
        public async Task<Result> Handle(SheepBuyCreateCommon request, CancellationToken cancellationToken)
        {
            var res= new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var list = new SheepBuy()
                {
                    BreedingSheepArchiveId=request.BreedingSheepArchiveId,
                    BuildingId=request.BuildingId,
                    ColumnsId=request.ColumnsId,
                    Sex = request.Sex,
                    GoodName= request.GoodName,
                    Unit = request.Unit,
                    Num= request.Num,
                    Price = request.Price,
                    Amount = request.Amount,
                    Settlement = request.Settlement,
                    Weight= request.Weight,
                    BuyerId= request.BuyerId,
                    Category = request.Category,
                    AbsrtactId = request.AbsrtactId,
                    BuyDate = request.BuyDate,
                    AccountingunitId=request.AccountingunitId,
                    Numberes= request.Numberes,
                    SheepTypesId= request.SheepTypesId,
                    VendorId= request.VendorId,
                    SerialNumber = request.SerialNumber,
                    DepotId = request.DepotId
                };
                SheepBuyRepository.Add(list);
                res.Code = (int)CommonEnumCode.success;
                res.Msg = "羊只采购新增成功";
            }
            catch (Exception)
            {

                res.Msg = "羊只采购新增失败";
                
            }
            return res;
        }
    }
}
